#pragma once
#include <cstdint>
#include <chrono>
#include <ctime>

namespace core {
	inline ::std::chrono::system_clock::duration now()
	{
		return std::chrono::system_clock::now().time_since_epoch();
	}

	template<typename duration>
	inline int64_t now_time()
	{
		return ::std::chrono::duration_cast<duration>(now()).count();
	}

	inline int64_t now_sec() {
		return ::std::chrono::duration_cast<::std::chrono::seconds>(now()).count();
	}

	inline int64_t now_millsec()
	{
		return ::std::chrono::duration_cast<::std::chrono::milliseconds>(now()).count();
	}

	inline ::std::time_t make_zone()
	{
		std::time_t t;
		std::time(&t);
		auto t1 = ::std::mktime(std::gmtime(&t));
		auto t2 = ::std::mktime(std::localtime(&t));
		return t2 - t1;
	}

	inline int64_t zone_secs()
	{
		static ::std::time_t timezone = make_zone();
		return timezone;
	}


	inline int64_t local_millsec()
	{
		return now_millsec() + zone_secs() * 1000;
	}

	inline int64_t local_sec()
	{
		return now_sec() + zone_secs();
	}

	enum time_const : int64_t
	{
		day_sec = 24 * 3600,
		day_msec = day_sec * 1000,
		hour_sec = 3600,
		hour_msec = hour_sec * 1000,
		week_sec = 7 * day_sec,
		week_msec = week_sec * 1000,
	};
}